package com.fun_ordering.service.impl;


import com.fun_ordering.components.PageResult;
import com.fun_ordering.mapper.FoStatusMapper;
import com.fun_ordering.pojo.FoStatus;
import com.fun_ordering.pojo.FoStatusExample;
import com.fun_ordering.service.FoStatusService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class FoStatusServiceImpl implements FoStatusService {

	@Autowired
	private FoStatusMapper foStatusMapper;
	
	/**
	 * 查询全部
	 */
	@Override
	public List<FoStatus> findAll() {
		return foStatusMapper.selectByExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<FoStatus> foStatusList = foStatusMapper.selectByExample(null);
		PageInfo<FoStatus> page=  new PageInfo<>(foStatusList);
		return new PageResult(page.getTotal(), page.getList());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(FoStatus foStatus) {
		foStatusMapper.insert(foStatus);		
	}

	
	/**
	 * 修改
	 */
	@Override
	public void update(FoStatus foStatus){
		foStatusMapper.updateByPrimaryKey(foStatus);
	}	
	
	/**
	 * 根据ID获取实体
	 * @param
	 * @return
	 */
	@Override
	public FoStatus findOne(Integer statusId){
		return foStatusMapper.selectByPrimaryKey(statusId);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(Integer[] statusIds) {
		for(Integer statusId:statusIds){
			foStatusMapper.deleteByPrimaryKey(statusId);
		}		
	}
	
	
	@Override
	public PageResult findPage(FoStatus foStatus, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		
		FoStatusExample example=new FoStatusExample();
		FoStatusExample.Criteria criteria = example.createCriteria();
		
		if(foStatus!=null){			
						if(foStatus.getOrderMsg()!=null && foStatus.getOrderMsg().length()>0){
				criteria.andOrderMsgLike("%"+foStatus.getOrderMsg()+"%");
			}	
		}

		List<FoStatus> foStatusList = foStatusMapper.selectByExample(example);
		PageInfo<FoStatus> page=  new PageInfo<>(foStatusList);
		return new PageResult(page.getTotal(), page.getList());
	}
	
}
